<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>新增/编辑操作员</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link href="${ctx}/css/IFS.css" rel="stylesheet" type="text/css" />
	<script src="${ctx}/js/boot.js" type="text/javascript"></script>
	<script src="${ctx}/js/crypto-js/core.js"></script>
    <script src="${ctx}/js/crypto-js/md5.js"></script>
	<style type="text/css">
	html, body {
		font-size:12px;padding:0;margin:0;border:0;height:100%;overflow:hidden;
	}
    </style>
</head>
<body>   
	 <form id="form1" method="post">
        <input name="operatorId" class="mini-hidden" />
        <input name="pwd_md5" class="mini-hidden" />
        <div style="padding-left:11px;padding-bottom:5px;">
            <table style="table-layout:fixed;">
                <tr>
                    <td style="width:70px;">用户名：</td>
                    <td style="width:150px;">    
                        <input name="userid" class="mini-textbox" required="true"  emptyText="请输入用户名"/>
                    </td>
                    <td style="width:70px;">姓名：</td>
                    <td style="width:150px;">    
                        <input name="operatorName" class="mini-textbox" required="true"  emptyText="请输入姓名"/>
                    </td>
                </tr>
                <tr>
                    <td >手机：</td>
                    <td >    
                        <input name="phone" class="mini-textbox" required="true" emptyText="请输入手机"/>
                    </td>
                    <td >密码：</td>
                    <td >    
                        <input name="pwd" class="mini-password" required="false" emptyText="密码默认是111111" onBlur="on_pwd_change()"/>
                    </td>
                </tr>
               
                <tr>
                    <td >角色：</td>
                    <td >    
                        <input name="roleId" class="mini-combobox" valueField="roleId" textField="roleName" url="${ctx}/acct/service/AcRoleService/getRole.do" />
                    </td>
                </tr>           
            </table>
        </div>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>
   
	<script type="text/javascript">
		mini.parse();
	
	    var form = new mini.Form("form1");
		
	    function SaveData() {
	        form.validate();
	        if (form.isValid() == false) return;
	        var o = form.getData();
	        var pwd_md5 = o.pwd_md5;
	        if(pwd_md5){
	        	o.pwd = pwd_md5;
	        }
	        $.ajax({
	            url: "${ctx}/acct/service/AcOperatorService/saveAcOperator.do",
				type: 'post',
	            data: o,
	            cache: false,
	            dataType : "json",
	            success : function(data) { 	
					var o = mini.decode(data);
			        if(o.success == true){
			        	// alert("保存成功");
			        	CloseWindow("save");
			        }else{
			        	alert(o.message);
			        }
				} 
	        });
	    }
	
	    ////////////////////
	    //标准方法接口定义
	    function SetData(data) {
	        if (data.action == "edit") {
	        	mini.getByName("userid").disable();
	            //跨页面传递的数据对象，克隆后才可以安全使用
	            data = mini.clone(data);
	            $.ajax({
	                url: "${ctx}/acct/service/AcOperatorService/inquiryAcOperator.do?operatorId=" + data.operatorId,
	                cache: false,
	                success: function (text) {
	                    var o = mini.decode(text);
	                    form.setData(o);
	                    form.setChanged(false);
	                }
	            });
	        }
	    }
	
	    function GetData() {
	        var o = form.getData();
	        return o;
	    }
	    function CloseWindow(action) {            
	        if (action == "close" && form.isChanged()) {
	            if (confirm("数据被修改了，是否先保存？")) {
	                return false;
	            }
	        }
	        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	        else window.close();            
	    }
	    function onOk(e) {
	        SaveData();
	    }
	    function onCancel(e) {
	        CloseWindow("cancel");
	    }
	    // 密码值改变事件
	    function on_pwd_change(){
	    	var pwd = mini.getByName("pwd").getValue();
	    	var md5 = CryptoJS.MD5(pwd).toString();
	    	mini.getByName("pwd_md5").setValue(md5);
	    }
    </script>

</body>
</html>
